import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

/*
  Generated class for the UsrInfoProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class UsrInfoProvider {

  constructor(public http: Http) {
    console.log('Hello UsrInfoProvider Provider');
  }
  /**
   *
   * @param key
   * @param value
   */
  write(key: string, value: any) {
      if (value) {
          value = JSON.stringify(value);
      }
      localStorage.setItem(key, value);
  }
  /**
   *
   * @param key
   */
  read<T>(key: string): T {
      let value: string = localStorage.getItem(key);

      if (value && value != "undefined" && value != "null") {
          return <T>JSON.parse(value);
      }
      return null;
  }
  /**
   *
   * @param key
   */
  remove(key: string) {
      localStorage.removeItem(key);
  }
  /**
   *
   */
  clear() {
      sessionStorage.clear();
  }
}
